import os
import json

SERVICE_NAME = "damai-mcp"
SERVICE_HOST = "0.0.0.0"
SERVICE_PORT = 8000
SERVICE_PATH = "/mcp"

# Model config (align with reference project)
MY_MODEL = "qwen3-32b"

SYSTEM_PROMPT_DAMAI_TIPS = (
    "你是一个演出活动推荐助手，基于输入的城市与活动列表生成简洁的观演建议。\n"
    "输入格式为：\n{\n  \"city\": \"城市名称\",\n  \"events\": [\n    {\"id\":\"活动ID\",\"title\":\"活动标题\",\"category\":\"品类\",\"venue\":\"场馆\",\"date\":\"时间\",\"min_price\":价格,\"url\":\"详情链接\"}\n    ...\n  ]\n}\n"
    "输出格式为一个字典：\n{\n  \"summary\": \"一句话总结，15-40字\",\n  \"highlights\": [\"亮点1\",\"亮点2\",\"亮点3\"],\n  \"recommendations\": [\n    {\"event_id\":\"ID\",\"reason\":\"推荐理由不超过40字\"},\n    {\"event_id\":\"ID\",\"reason\":\"推荐理由不超过40字\"}\n  ]\n}\n"
    "严格只输出上述字典，内容面向普通用户，可读性强，不包含与购票相关的操作指引。"
)

# City mapping (can be overridden via env DAMAI_CITY_MAP json)
DEFAULT_CITY_ID_MAP = {
    "北京": "101010100",
    "上海": "101020100",
    "广州": "101280101",
    "深圳": "101280601",
    "杭州": "101210101",
    "南京": "101190101",
    "苏州": "101190401",
    "成都": "101270101",
    "重庆": "101040100",
    "武汉": "101200101",
    "西安": "101110101",
    "长沙": "101250101",
    "郑州": "101180101",
    "天津": "101030100",
    "青岛": "101120201",
    "大连": "101070201",
    "沈阳": "101070101",
    "哈尔滨": "101050101",
    "昆明": "101290101",
    "贵阳": "101260101",
    "南宁": "101300101",
    "厦门": "101230201",
    "福州": "101230101",
    "宁波": "101210401",
    "无锡": "101190201",
    "合肥": "101220101",
    "济南": "101120101",
    "石家庄": "101090101",
    "太原": "101100101",
    "南昌": "101240101",
    "呼和浩特": "101080101",
    "乌鲁木齐": "101130101",
}

def load_city_map() -> dict:
    raw = os.getenv("DAMAI_CITY_MAP", "")
    if raw:
        try:
            user_map = json.loads(raw)
            if isinstance(user_map, dict):
                return {**DEFAULT_CITY_ID_MAP, **user_map}
        except Exception:
            pass
    return DEFAULT_CITY_ID_MAP

CITY_ID_MAP = load_city_map()
